/*
 * @Author: yangzonglong
 * @Date: 2021-05-08 15:40:53
 * @version: v1.0.0
 * @Descripttion: 
 * @LastEditors: yangzonglong
 * @LastEditTime: 2021-07-12 14:47:14
 * @Auditor: 
 */
import axios from 'axios';
import { units } from '@library';
import { FormProps, FormDataProps } from './../../interface';

export async function getForm(formId: string, dataId?: string): Promise<[FormProps, FormDataProps] | []> {
  try {
    const form = await units.serverLoading('/bk/api/fd/Form/findOne', { where: { id: formId } });
    
    let formData = { data: '' };
    if(dataId) {
      formData = await units.serverLoading('/bk/api/fd/FormData/findOne', { where: { id: dataId } });
    }

    return [form, formData]
  } catch (error) {
    return []
  }
}

export async function getLformView(content: string, data: string) {
  try {
    let { data: processedHTML } = await axios({
      url: '/fd/preview_design_content',
      method: 'POST',
      data: { content, data }
    })
    return processedHTML
  } catch (error) {
    console.log(error)
    return ''
  }
}